//
//  XGMessageCell.m
//  XGSeeDetails
//
//  Created by 小果 on 16/8/29.
//  Copyright © 2016年 小果. All rights reserved.
//

#import "XGMessageCell.h"
#import "XGCellModel.h"
#import "XGCellFrame.h"
@interface XGMessageCell ()
@property (nonatomic, weak) UIImageView *headIcon;

@property (nonatomic, weak) UILabel *nameLab;

@property (nonatomic, weak) UILabel *introLab;

@property (nonatomic, weak) UIView *sepLine;

@property (nonatomic, weak) UIImageView *seeView;

@end
@implementation XGMessageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        // 设置Cell中的控件
        [self setupCellWithInsideContent];
    
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    return self;
}

#pragma mark - 设置Cell中的内容
-(void)setupCellWithInsideContent{
    UIImageView *headIcon = [[UIImageView alloc] init];
    headIcon.opaque = YES;
    self.headIcon = headIcon;
    [self.contentView addSubview:headIcon];
    
    UILabel *nameLab = [[UILabel alloc] init];
    nameLab.opaque = YES;
    nameLab.font = [UIFont boldSystemFontOfSize:18];
    self.nameLab = nameLab;
    [self.contentView addSubview:nameLab];
    
    UILabel *introLab = [[UILabel alloc] init];
    introLab.numberOfLines = 0;
    introLab.opaque = YES;
    introLab.font = [UIFont boldSystemFontOfSize:16];
    introLab.textColor = [UIColor colorWithRed:127/255.0 green:127/255.0 blue:127/255.0 alpha:1.0];
    self.introLab = introLab;
    [self.contentView addSubview:introLab];
    
    UIImageView *seeView = [[UIImageView alloc] init];
    seeView.contentMode = UIViewContentModeScaleAspectFit;
    seeView.backgroundColor = [UIColor redColor];
    seeView.image = [UIImage imageNamed:@"group_pay_arrow"];
    self.seeView = seeView;
    [self.contentView addSubview:seeView];
    
    UIView *sepLine = [[UIView alloc] init];
    sepLine.backgroundColor = [UIColor colorWithRed:233/255.0 green:233/255.0 blue:231/255.0 alpha:1.0];
    self.sepLine = sepLine;
    [self.contentView addSubview:sepLine];
    
}

-(void)setCellFrame:(XGCellFrame *)cellFrame{
    _cellFrame = cellFrame;
    
    [self setupMessageFrame];
    
    [self setupMessageContent:cellFrame];
}

-(void)setupMessageFrame{
    self.headIcon.frame = self.cellFrame.iconF;
    self.introLab.frame = self.cellFrame.introF;
    self.nameLab.frame = self.cellFrame.nameF;
    self.sepLine.frame = self.cellFrame.sepLineF;
    self.seeView.frame = self.cellFrame.seeF;
    if (self.cellFrame.isOpened == YES){
        self.seeView.transform = CGAffineTransformMakeRotation(-M_PI);
    }else{
        self.seeView.transform = CGAffineTransformIdentity;

    }
}

-(void)setupMessageContent:(XGCellFrame *)cellFrame{
    XGCellModel *model = cellFrame.cellModel;
    
    self.headIcon.image = [UIImage imageNamed:model.icon];
    self.nameLab.text = model.name;
    self.introLab.text = model.intro;

}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.headIcon.layer.cornerRadius = self.headIcon.width * 0.5;
    self.headIcon.layer.masksToBounds = YES;
    
}
@end